//----------发送http请求----------
function sendHttpRequest(method, url, data, output){
	//发送get或post请求
	if(method == "get"){
		xhrGet(url, data);
	}
	else if(method == "post"){
		ajaxPost(url, data, function(res) {
			//outputData = res;
			output(res);
		});
	}
	
}
//----------发送get请求----------
function xhrGet(url, data){
	var xhr = new XMLHttpRequest();
	xhr.onreadystatechange = function(){
	    if( xhr.readyState == 4){
	         if( xhr.status >= 200 && xhr.status < 300 || xhr.status == 304){
	             info.innerHTML = xhr.responseText;
	          }
	     }
	};

	// 每次需要发请求需要做两步：
	xhr.open("get", url, true);
	xhr.send(data);
}
//----------发送post请求----------
//ajax 对象
function ajaxObject() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } 
    catch (e) {
        // Internet Explorer
        try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("您的浏览器不支持AJAX！");
                return false;
            }
        }
    }
    return xmlHttp;
}
//ajax post请求：
function ajaxPost ( url , data, fnSucceed ) {
    var ajax = ajaxObject();
    ajax.open( "post" , url , true );
    ajax.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" );
    ajax.onreadystatechange = function () {
        if( ajax.readyState == 4 ) {
            if( ajax.status == 200 ) {
                fnSucceed( ajax.responseText );
            }
        }
    }
    ajax.send( data );
}